package com.example.applicationview.kotlin

import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

data class People(val name: String){

}
suspend fun main(args: Array<String>) {
    val p = People("yangyang")
    var p1 = null
    var r1 = p1?.let{
        println(p.toString())
        12
    }
//    testRunBlocking()
    val job = GlobalScope.launch {
        delay(1000)
        println("协程执行结束 -- 线程id：${Thread.currentThread().id}")
    }
    job.join()
    println(r1)
}

//runBlocking启动的协程任务会阻断当前线程，直到该协程执行结束
private fun testRunBlocking() = runBlocking {
    repeat(8) {
        println("协程执行$it 线程id：${Thread.currentThread().id}")
        delay(1000)
    }
}

//val job = GlobalScope.launch {
//    delay(1000)
//    println("协程执行结束 -- 线程id：${Thread.currentThread().id}")
//}

